package com.example.android.ui.hb;

import com.example.android.bean.BaseBean;
import com.example.android.bean.Goods;

import java.util.List;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;

public class HBPresenter implements HBContract.IHBPresenter {
    HBContract.IHBModel hbModel;
    private HBContract.IHBView hbView;
    public HBPresenter(HBContract.IHBView hbView){
        this.hbView =hbView;
        hbModel = new HBModel();
    }

    @Override
    public void getHbList() {
        hbModel.getHBList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<BaseBean<List<Goods>>>() {
                    @Override
                    public void accept(BaseBean<List<Goods>> listBaseBean) throws Throwable {
                        hbView.getHBListSuccess(listBaseBean);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Throwable {
                        hbView.getHBListError(throwable);
                    }
                });
    }
}
